<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0" id="list" lay-title="我的银行卡">
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
			  
			<div>
				<button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
				<button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
			</div>
            <table class="layui-hide" id="list-table" lay-filter="list-table"></table>
			<script type="text/html" id="list-toolbar">
			  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</script>
			<script type="text/html" id="Time">
			  		{{layui.admin.dateFormat(d.add_time)}}
			</script>
			<script type="text/html" id="list-tableF">
							<input type="checkbox" name="admin_status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF"
			   value="{{ d.bank_status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.bank_status == 1 ? 'checked' : '' }}>
			</script>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
   //表格数据渲染
  var formurl='bank/bank_form',formarea=['400px', '400px'];
  layui.use(['table','form'], function () {
	  var table = layui.table
	  ,form = layui.form
	  ,$ = layui.$;
	  layui.admin.initlist(table,'agent_bank/list',195,[[
		{type:'checkbox'}
        ,{field:'bank_id', title: 'ID', width:100}
        ,{field:'bank_name', title: '银行名称', width:200}
        ,{field:'account_name', title: '开户人姓名', width: 200}
        ,{field:'bank_account', title: '银行卡号', minWidth:200}
		,{field:'create_time', title:'创建时间', width:200}
		,{field:'bank_status', title:'状态', width:100,templet: '#list-tableF',}
		,{title:'操作', toolbar: '#list-toolbar', width:150}
      ]])
	  //监听表格表单操作
	  form.on('switch(list-tableF)', function(obj) {
	  	var json = JSON.parse(decodeURIComponent($(this).data('json')));
	  	json = table.clearCacheKey(json);
	  	json.bank_status == 1 ? json.bank_status = 2 : json.bank_status = 1;
	  	layui.admin.ajax('agent_bank/update',{
	  		bank_status:json.bank_status,
	  		bank_id:json.bank_id
	  	}).then((res) => {
	  		layui.table.reload('list-table');
	  	}).catch((res) => {});
	  });
	//监听表格操作事件
	table.on('tool(list-table)', function(obj){
	  var data = obj.data;
	  //删除
	  if(obj.event === 'del'){
		layer.confirm('确定删除'+data.bank_name+'?', function(index){
		  layui.admin.delF(table,'agent_bank/delete',{bank_id:data.bank_id});
		});
	  } else if(obj.event === 'edit'){//编辑
		layui.admin.pupF('编辑分组',formarea,formurl,2,data)
	  }
	});
	//监听行双击事件
	table.on('rowDouble(list-table)', function(obj){
		//查看详情
	  layui.admin.pupF('分组详情',formarea,formurl,3,obj.data);
	});
	var active = {
	  //多行删除
	  batchdel:function(){
		  layui.admin.delsF(table,'agent_bank/delete','bank_id')
	  }
	  //添加
	  ,add: function(othis){
		layui.admin.pupF('添加分组',formarea,formurl,1,{})
	  }
	}; 
	//操作dom
	$('.layui-btn.layuiadmin-btn-list').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
	});
	
  });
</script>